package net.kts.story.progress;

import net.kts.transrate.TranslateService;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class StoryProgressDialog {
	private static ProgressDialog progressDialog;
	private static Context context;

	public static void setActivity(Context context) {
		updateActivity(context);
	}

	public static void updateActivity(Context context) {
		StoryProgressDialog.context = context;
		createProgressDiaglog();
	}

	private static void createProgressDiaglog() {
		progressDialog = new ProgressDialog(context);
		progressDialog.setIndeterminate(true);
		progressDialog.setMessage(TranslateService.translateRepository("Please wait"));
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setCancelable(false);
	}

	public static ProgressDialog build(Context context) {
		ProgressDialog progressDialog = new ProgressDialog(context);
		progressDialog.setIndeterminate(true);
		progressDialog.setMessage(TranslateService.translateRepository("Please wait"));
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		return progressDialog;
	}

	public static void showProgressDiaglog() {
		progressDialog.setMessage(TranslateService.translateRepository("Please wait"));
		progressDialog.show();
	}

	public static void dismissProgressDiaglog() {
		handler.sendEmptyMessage(1);
	}
	public static void doItExecute(Runnable runnable){
		handler.post(runnable);
	}
	
	private final static Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			
			switch (msg.what) {
			case 0:
				progressDialog.show();
				break;
			default:
				progressDialog.dismiss();
				break;
			}
		}
	};
}
